﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

using System.Xml.Serialization;
using System.ComponentModel;

namespace XEvents.Library
{
    public abstract class XEObjectBase : XEventBase
    {
        internal string name;
        internal string object_type;
        internal Guid package_guid;
        internal string description;
        internal int capabilities;
        internal string capabilities_desc;
        internal string type_name;
        internal Guid type_package_guid;
        internal int type_size;

        /// <summary>
        /// Package for this Object
        /// </summary> 
        [DescriptionAttribute("Package for this Object"), ReadOnlyAttribute(true)]
        [XmlIgnore()]
        public Package Package
        {
            get
            {
                return (from p in Server.MetaData.Packages
                        where p.Guid == this.package_guid
                        select p).ElementAtOrDefault(0);
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        /// <summary>
        /// Name
        /// </summary>
        [DescriptionAttribute("Name"), ReadOnlyAttribute(true)]
        [XmlAttribute("Name")]
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        /// <summary>
        /// Description
        /// </summary>
        [DescriptionAttribute("Description"), ReadOnlyAttribute(true)]
        [XmlAttribute("Description")]
        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        internal XEObjectBase(dm_xe_object obj, SqlServer server)
            : base(server)
        {
            this.name = obj.name;
            this.description = obj.description;
            this.capabilities = obj.capabilities;
            this.capabilities_desc = obj.capabilities_desc;
            this.object_type = obj.object_type;
            this.package_guid = obj.package_guid;
            this.type_name = obj.type_name;
            this.type_package_guid = obj.type_package_guid;
            this.type_size = obj.type_size;
        }

        internal XEObjectBase(SqlServer server)
            : base(server)
        { }
    }
}
